<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="keywords" content="hsiangleev,layui扩展">
    <title>layui扩展树文档</title>
    <link rel="stylesheet" href="{$sys_url.plug}/eleTree/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="{$sys_url.plug}/eleTree/eleTree/eleTree.css" media="all">

    <style>
        html,body{
            width: 80%;
            margin: 0 auto;
            background-color: #fff;
            padding: 15px 0px 30px 0px;
        }
        .eleTree{
            width: 600px;
            height: 900px;
            border: 1px solid #ccc;
            overflow: hidden;
            overflow-y: auto;
        }
        .red{
            color: #ff4200;
        }
        .blue{
            color: #01AAED;
        }
        a:hover{
            color: #01AAED;
        }

        .nav{
            position: fixed;
            right: 25px;
            top: calc(50% - 120px);
            border: 1px solid #d2d2d2;
            background-color:#fff;
            z-index: 100000;
        }
        .nav-title{
            background-color: #F8F8F8;
            padding:0 80px 0 20px;
            margin: 0px;
            height: 42px;
            line-height: 42px;
            border-bottom: 1px solid #eee;
        }
        .nav ul{
            padding:10px 0px 10px 35px;
        }
        .nav ul li{
            padding: 5px 0px;
            list-style-type: decimal;
        }
        .nav ul a{
            color: #333;
            font-size: 14px;
            text-decoration: none;
        }
    </style>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title site-title">
    <legend>
        <a name="use">用户权限</a>
    </legend>
</fieldset>
<button type="button" class="layui-btn layui-btn-normal btnAdd">确认</button>
<div class="content1">
    <div class="eleTree ele1"></div>
</div>


<script src="{$sys_url.plug}/eleTree/layui/layui.js"></script>
<script>
    var ids = '';

    layui.config({
        base: "{$sys_url.plug}/eleTree/layui/lay/mymodules/"
    }).use(['jquery','table','eleTree','code'], function(){
        var $ = layui.jquery;
        var eleTree = layui.eleTree;
        var data= <?php echo $data;?>

        var e1 = eleTree.render({
            elem: '.ele1',
            data: data,
            showCheckbox: true,
            draggable:true
        });
        e1.expandAll();
        e1.expandAll();

        $('.btnAdd').on('click',function(){

          var selData =  e1.getChecked(false,true);

            $.each(selData,function(key,val){
                if(ids == ''){
                   ids = val.id;
                }else{
                   ids += ','+val.id;
                }
            });

            $.ajax({
                url: '{$sys_url.ctr}/node_ajax',
                type: 'post',
                data: {ids: ids ,id_role:{$id}},
                dataType: "json",
                beforeSend: function() {
                    console.log(JSON.stringify(data.field));
                },
                success: function(data) {
                   ids = '';
                    if (data.code == 1) {
                        var index = parent.layer.getFrameIndex(window.name);
                        //获取当前窗口索引
                        layer.alert('操作成功', {icon: 1});

                    } else {
                        layer.alert('抱歉，系统繁忙，请稍后再试！', {icon: 2});
                    }
                },
                error: function(data) {
                    ids = '';
                    //do something
                    console.log(data);
                    layer.msg('与服务器连接失败', {icon: 2});
                }
            });



        });
    });


    //新增

</script>

</body>
</html>